﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace iLangl.LanguageWire.DAL.LanguageWireDAL.RealStorage
{
	public class LWStorageConfiguration: ConfigurationSection
	{
		private static ConfigurationProperty userNameProperty;
		private static ConfigurationProperty passwordProperty;
		private static ConfigurationProperty APICustomerIDProperty;

		private static LWStorageConfiguration instance;
		private static ConfigurationPropertyCollection properties;

		static LWStorageConfiguration()
		{
			userNameProperty = new ConfigurationProperty(
			  "userName",
			  typeof(String),
			  null, 
			  ConfigurationPropertyOptions.IsRequired);

			passwordProperty = new ConfigurationProperty(
			  "passwordProperty",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);

			APICustomerIDProperty = new ConfigurationProperty(
			  "APICustomerIDProperty",
			  typeof(String),
			  null,
			  ConfigurationPropertyOptions.IsRequired);


			properties = new ConfigurationPropertyCollection();
			properties.Add(userNameProperty);
			properties.Add(passwordProperty);
			properties.Add(APICustomerIDProperty);
		}

		private static object mutex = new object();
		/// <summary>
		/// The instance of the ConfigurationProperty.
		/// </summary>
		public static LWStorageConfiguration Instance
		{
			get
			{
				if (instance == null)
				{
					lock (mutex)
					{
						if (instance == null)
						{
							instance = ConfigurationManager.GetSection("LWStorageConfiguration") as LWStorageConfiguration;
						}
					}
				}
				return instance;
			}
		}

		/// <summary>
		/// User for connection to LW API
		/// </summary>
		public String UserName
		{
			get
			{
				return base[userNameProperty] as String;
			}
		}

		/// <summary>
		/// User Password for connection to LW API
		/// </summary>
		public String Password
		{
			get
			{
				return base[passwordProperty] as String;
			}
		}

		public Guid APICustomerID {
			get
			{
				return new Guid(base[APICustomerIDProperty] as String);
			}
		}

		protected override ConfigurationPropertyCollection Properties
		{
			get
			{
				return properties;
			}
		}

		
	}
}
